package main

import (
	"fmt"
	"sync"
	"time"
)

var wg sync.WaitGroup

func main() {

	for i := 0; i < 5; i++ {
		wg.Add(1) // add 1 goroutine
		go func(x int) {
			time.Sleep(time.Second * 1)
			fmt.Println(x)
			wg.Done() // substruct 1 goroutine
		}(i)
	}
	wg.Wait() // wait goroutine to 0

}
